package com.wave.spring.config;

import jmind.base.util.IOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;

/**
 * Created by lv on 2017/8/26.
 */
@Configuration
@PropertySource("classpath:test.properties")
public class ELConfig {
    @Value("I love you")
    private String normal;
    @Value("#{systemProperties['os.name']}")
    private String osName;

    @Value("${os.name}")
    private String osName2;


    @Value("#{ T(java.lang.Math).random()*100}")
    private double randomNumber;
    @Value("#{myService.url}")
    private String url;

    @Value("classpath:myfile.txt")
    private Resource myfile;

    @Value("http://baidu.com")
    private Resource baidu;

    @Value("${book.name}")
    private String bookName;
    @Autowired
    Environment environment;



    public void output() {
        try {
            System.err.println(normal+"--"+osName+"--"+osName2+"--"+bookName+"--"+randomNumber+"--"+url);
            System.err.println(IOUtil.stream2String(baidu.getInputStream()));
            System.err.println(environment.getProperty("book.name"));
            System.err.println(environment.resolvePlaceholders("${book.name}"));

        }catch (Exception e){
            e.printStackTrace();

        }
    }
}
